home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / sql-bench / innotest1a < prev    next >
Encoding:
Text File  |  2003-01-22  |  3.9 KB  |  108 lines  |  [TEXT/ttxt]

  1. #!/usr/bin/perl
  2. ############################################################################
  3. #     Stress test for MySQL/InnoDB combined database
  4. #     (c) 2002 Innobase Oy & MySQL AB
  5. #
  6. ############################################################################
  7.  
  8. use DBI;
  9. use Benchmark;
  10.  
  11. $opt_loop_count = 200000;
  12.  
  13. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  14. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  15.  
  16. print "Innotest1a: MySQL/InnoDB stress test in Perl\n";
  17. print "-------------------------------------------\n";
  18. print "This is a randomized stress test for concurrent inserts,\n";
  19. print "updates, deletes, commits and rollbacks. The test will generate\n";
  20. print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
  21. print "\n";
  22. print "You should run innotest1, innotest1a, and innotest1b concurrently.\n";
  23. print "The thing to watch is that the server does not crash or does not\n";
  24. print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
  25. print "warnings about MySQL lock reservations can appear in the .err log.\n";
  26. print "The test will run very long, even several hours. You can kill\n";
  27. print "the perl processes running this test at any time and do CHECK\n";
  28. print "TABLE on table innotest1 in the 'test' database.\n";
  29. print "\n";
  30. print "Some of these stress tests will print a lot of SQL errors\n";
  31. print "to the standard output. That is not to be worried about.\n";
  32. print "You can direct the output to a file like this:\n";
  33. print "perl innotest1 > out1\n\n";
  34.  
  35. print "Generating random keys\n";
  36. $random[$opt_loop_count] = 0;
  37. $rnd_str[$opt_loop_count] = "a";
  38.  
  39. for ($i = 0; $i < $opt_loop_count; $i++) {
  40.  
  41.     $random[$i] = ($i * 63857) % $opt_loop_count;
  42.  
  43.       if (0 == ($random[$i] % 3)) {
  44.           $rnd_str[$i] = "kjgclgrtfuylfluyfyufyulfulfyyulofuyolfyufyufuyfyufyufyufyufyyufujhfghd";
  45.     } else { if (1 == ($random[$i] % 3)) {
  46.         $rnd_str[$i] = "khd";
  47.     } else { if (2 == ($random[$i] % 3)) {
  48.         $rnd_str[$i] = "kh";
  49.     }}}
  50.  
  51.     for ($j = 0; $j < (($i * 764877) % 20); $j++) {
  52.         $rnd_str[$i] = $rnd_str[$i]."k";
  53.     }    
  54. }
  55.  
  56. ####
  57. ####  Connect
  58. ####
  59.  
  60. $dbh = $server->connect()
  61. || die $dbh->errstr;
  62.  
  63.  
  64. $dbh->do("set autocommit = 0");
  65.  
  66. for ($i = 0; $i < 1; $i++) {
  67.     print "loop $i\n";
  68.  
  69.     for ($j = 1; $j < $opt_loop_count - 10; $j = $j + 2) {
  70.         $dbh->do(
  71.         "insert into innotest1 (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')");
  72.         $dbh->do("update innotest1 set B = '".$rnd_str[$j + 2]."' where A = ".$random[$j + 5]);
  73.         $dbh->do("update innotest1 SET D = D + 1 where A =".(($j - 1) / 2 - 777));
  74.         $dbh->do("update innotest1 set B = '".$rnd_str[$j + 8]."' where A =".(($j - 1) / 2 - 770));
  75.         $dbh->do("delete from innotest1 where A = ".$random[$random[$j]]);
  76.  
  77.         fetch_all_rows($dbh, "select b, c from innotest1 where a > ".$random[$j]." and a < ".($random[$j] + 7));
  78.         
  79.         if (0 == ($j % 37)) {
  80.             $dbh->do("commit");
  81.         }
  82.  
  83.         if (0 == ($j % 533)) {
  84.             $dbh->do("rollback");
  85.         }        
  86.  
  87.         if (0 == ($j % 537)) {
  88.         print fetch_all_rows($dbh, "select c from innotest1 where c = '".$rnd_str[$j - 67]."'");
  89.         print fetch_all_rows($dbh, "select b from innotest1 where b = '".$rnd_str[$j - 688]."'");
  90.         print fetch_all_rows($dbh, "select b, c from innotest1 where c = '".$rnd_str[$j - 67]."'");
  91.         print fetch_all_rows($dbh, "select b, c from innotest1 where b = '".$rnd_str[$j - 622]."'");
  92.         print fetch_all_rows($dbh, "select a, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
  93.         print fetch_all_rows($dbh, "select a, b, c from innotest1 where b = '".$rnd_str[$j - 644]."'");
  94.         print fetch_all_rows($dbh, "select d, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
  95.         print fetch_all_rows($dbh, "select d, b, c from innotest1 where b = '".$rnd_str[$j - 677]."'");
  96.         print "\n";
  97.         }
  98.  
  99.         if (0 == (($j - 1) % 1000)) {
  100.             print "round $j\n";
  101.         }
  102.     }    
  103.     
  104.     $dbh->do("commit");
  105. }                
  106.  
  107. $dbh->disconnect;                # close connection
  108.